package com.zwface.demo.function.mine;

import android.view.View;

import androidx.lifecycle.ViewModelProviders;

import com.zwface.demo.R;
import com.zwface.demo.base.BaseFragment;
import com.zwface.demo.databinding.FragmentMineBinding;
import com.zwface.demo.function.login.LoginActivity;
import com.zwface.demo.function.main.mvvm.MainViewModel;
import com.zwface.demo.utils.SharedPreferenceUtils;

/**
 * created by      张中文
 * on:             2020/4/28 16:28
 * 描述：
 */
public class MineFragment extends BaseFragment<FragmentMineBinding> implements View.OnClickListener
{
    private MainViewModel viewModel;

    @Override
    protected int onLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void onInitBinding(FragmentMineBinding binding) {
        super.onInitBinding(binding);
        viewModel = ViewModelProviders.of(this).get(MainViewModel.class);
        binding.setData(viewModel);
    }

    @Override
    protected void onInitComponent() {
        super.onInitComponent();
        initTopbar();
        binding.btnExit.setOnClickListener(this);
        viewModel.getUserInfo();
    }

    private void initTopbar(){
        binding.topbar.setTitle("我的");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_exit:
                SharedPreferenceUtils.setParam(context,SharedPreferenceUtils.USER_ID,"");
                SharedPreferenceUtils.setParam(context,SharedPreferenceUtils.USER_NAME,"");
                SharedPreferenceUtils.setParam(context,SharedPreferenceUtils.USER_STUNO,"");
                SharedPreferenceUtils.setParam(context,SharedPreferenceUtils.USER_FACE,"");
                gotoActivity(LoginActivity.class,null);
                break;
        }
    }
}
